// 统一封装接口
import http from '@/utils/request.js'
// 登录接口
export const loginAPI = (data) => http({
  url: '/v1_0/authorizations',
  method: 'POST',
  data: data // body传参的时候用data
})

// 获取所有频道
export const getAllChannelsAPI = () => http({
  url: '/v1_0/channels'
})

// 获取用户的频道
// 没有登录的话返回用户默认选择的频道列表
export const getUserChannelsAPI = () => http({
  url: '/v1_0/user/channels'
})

// 设置用户的频道（重置式）
export const setUserChannelsAPI = (data) => http({
  method: 'PUT',
  url: '/v1_0/user/channels',
  data: data
})

// 删除用户指定的频道
// 这里直接传入频道ID
export const delUserChannelsAPI = (params) => http({
  method: 'DELETE',
  url: `/v1_0/user/channels/${params}`
})

// 获取文章新闻推荐
export const getArticles = (params) => http({
  url: '/v1_0/articles',
  params: params // 查询的时候用这个
})

// 对文章不喜欢
export const articleDislikesAPI = (data) => http({
  url: '/v1_0/article/dislikes',
  method: 'POST',
  data: data
})

// 举报
export const articleReportsAPI = (data) => http({
  url: '/v1_0/article/reports',
  method: 'POST',
  data: data
})

// 搜索联想菜单
export const suggestionAPI = (params) => http({
  url: '/v1_0/suggestion',
  params: params
})

// 搜索结果
export const searchApi = (params) => http({
  url: '/v1_0/search',
  params: params
})

// 获取文章详情
export const articlesApi = (params) => http({
  url: `/v1_0/articles/${params}`
})

// 关注用户
export const followingsAPI = (data) => http({
  url: '/v1_0/user/followings',
  method: 'POST',
  data: data
})

// 取消关注用户
export const followingsDelAPI = (params) => http({
  url: `/v1_0/user/followings/${params}`,
  method: 'DELETE'
})

// 对文章点赞
export const likingsAPI = (data) => http({
  url: '/v1_0/article/likings',
  method: 'POST',
  data: data
})

// 取消对文章点赞
export const likingsDelAPI = (params) => http({
  url: `/v1_0/article/likings/${params}`,
  method: 'DELETE'
})

// 获取评论或评论回复
export const commentsAPI = (params) => http({
  url: '/v1_0/comments',
  params: params
})

// 点赞评论
export const commentlikingsAPI = (data) => http({
  url: '/v1_0/comment/likings',
  method: 'POST',
  data: data
})

// 取消对评论点赞
export const commentDelApi = (params) => http({
  url: `/v1_0/comment/likings/${params}`,
  method: 'DELETE'
})

// 对文章或者评论进行评论
export const commentsendAPI = (data) => http({
  url: '/v1_0/comments',
  method: 'POST',
  data: data
})

// 收藏文章
export const articlecollectionsApi = (data) => http({
  url: '/v1_0/article/collections',
  method: 'POST',
  data: data
})

// 取消收藏文章
export const articlecollectionsDelApi = (params) => http({
  url: `/v1_0/article/collections/${params}`,
  method: 'DELETE'
})

// 获取用户个人资料
export const userprofileApi = () => http({
  url: '/v1_0/user/profile'
})

// 获取用户基本信息
export const userinfoAPI = () => http({
  url: '/v1_0/user'
})

// 编辑用户照片资料
// 参数不能使用对象形式传入,要不然还是会变成JSON形式,所以通过参数传入
export const userphotoeditAPI = (data) => http({
  url: '/v1_0/user/photo',
  method: 'PATCH',
  data: data
})

// 编辑用户个人资料
// /v1_0/user/profile
export const edituserprofileAPI = (data) => http({
  url: '/v1_0/user/profile',
  method: 'PATCH', // 局部更新
  data: data
})

// 刷新用户token
export const refToken = () => http({
  url: '/v1_0/authorizations',
  method: 'PUT',
  headers: { // 手动添加请求头
    Authorization: 'Bearer ' + localStorage.getItem('refresh_token')
  }
})
